package com.personal.system.controller.content;

import com.personal.common.result.Result;
import com.personal.system.entity.vo.ArticleDTO;
import com.personal.system.service.content.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/article")
@RequiredArgsConstructor
@Api(tags = "后台文章管理")
public class ArticlesController {

    private final ArticleService articleService;


    @PostMapping(value = "/list")
    @ApiOperation(value = "文章列表", httpMethod = "POST", response = Result.class, notes = "文章列表")
    public Result selectArticleList(@RequestBody Map<String,Object> map) {
        return articleService.selectArticleList(map);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value = "文章详情", httpMethod = "GET", response = Result.class, notes = "文章详情")
    public Result selectArticleById(Long id) {
        return articleService.selectArticleById(id);
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "保存文章", httpMethod = "POST", response = Result.class, notes = "保存文章")
    public Result insertArticle(@RequestBody ArticleDTO article) {
        return  articleService.insertArticle(article);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改文章", httpMethod = "POST", response = Result.class, notes = "修改文章")
    public Result updateArticle(@RequestBody ArticleDTO article) {
        return articleService.updateArticle(article);
    }


    @DeleteMapping(value = "/deleteBatch")
    @ApiOperation(value = "批量删除文章", httpMethod = "DELETE", response = Result.class, notes = "批量删除文章")
    public Result deleteBatchArticle(@RequestBody List<Long> ids) {
        return articleService.deleteBatchArticle(ids);
    }

    @PostMapping(value = "/top")
    @ApiOperation(value = "置顶文章", httpMethod = "POST", response = Result.class, notes = "置顶文章")
    public Result topArticle(@RequestBody ArticleDTO article) {
        return articleService.topArticle(article);
    }

    @PostMapping(value = "/pubOrShelf")
    @ApiOperation(value = "发布或下架文章", httpMethod = "POST", response = Result.class, notes = "发布或下架文章")
    public Result psArticle(@RequestBody ArticleDTO article) {
        return articleService.psArticle(article);
    }

    @PostMapping(value = "/baiduSeo")
    @ApiOperation(value = "批量文章SEO", httpMethod = "POST", response = Result.class, notes = "文章SEO")
    public Result seoBatch(@RequestBody List<Long> ids) {
        return articleService.seoBatch(ids);
    }

    @GetMapping(value = "/reptile")
    @ApiOperation(value = "文章爬虫", httpMethod = "GET", response = Result.class, notes = "文章爬虫")
    public Result reptile(String url) {
        return articleService.reptile(url);
    }

    @GetMapping(value = "/randomImg")
    @ApiOperation(value = "随机获取一张图片", httpMethod = "GET", response = Result.class, notes = "随机获取一张图片")
    public Result randomImg() {
        return articleService.randomImg();
    }

    @PostMapping(value = "/pdfAnalysis")
    @ApiOperation(value = "解析pdf文件保存", httpMethod = "POST", response = Result.class, notes = "解析pdf文件保存")
    public Result pdfAnalysis(@RequestParam("file") MultipartFile file) throws IOException {

        return articleService.pdfAnalysis(file);
    }

}
